#!/usr/bin/env python3
"""
Tongyi Lingma API 模拟器
基于监听到的真实请求构建的API调用脚本
"""

import requests
import json
import time
from typing import Dict, Any
import uuid

class LingmaAPISimulator:
    def __init__(self):
        # 从监听数据中提取的认证信息
        self.base_url = "https://lingma-api.tongyi.aliyun.com"
        
        # 用户信息 - 从lingma1.txt提取
        self.user_info = {
            "id": "218263656662403745",
            "name": "黄星炤", 
            "orgId": "66cee5640a8d490b069d8cea",
            "orgName": "小鹏汽车",
            "yxUid": "66e164fd81a12b9a0a675161"
        }
        
        # 设备信息 - 从请求头提取
        self.device_info = {
            "cosy_version": "2.5.18",
            "cosy_machineid": "34363438-6639-412d-b430-30773a66662d",
            "cosy_clientip": "169.254.197.104",
            "cosy_clienttype": "0",
            "login_version": "v2"
        }
        
        # 认证令牌 - 从lingma2.txt提取最新的
        self.auth_tokens = {
            "bearer_token": "COSY.eyJjb3N5VmVyc2lvbiI6IjIuNS4xOCIsImlkZVZlcnNpb24iOiIiLCJpbmZvIjoidXRJRkIrc29Ba05PK3c5MmtCeHROS2lVQ090SVpkTGdIdkhxUloveEkyT3pWTmVrVjBISUZXNU1ZZU5RclVGNWRpUkI3aDgxNkVGU212OEY2cUt1b3ZlZWFFYU0yUmN5WmhaUWI0RW1aNEFqWnZUWWRwWHY2ZG1qZlpBWko5NE9VSjFEM2hBdlB2UVFXS0RxbzNZMFdYeGo0ZER6NGV1WXhjTCtaeVVNc29vanNadzZOSkU0OXFISXdyVmJ1UEFocmU5VlljN0Q0dWtPOExVOFNYcFY5YmtkUHZObVNFSnd1WldZcXNmbHFkOUZwUVBlaHZWdGpqbkdWQlZOOEZ3U0tQOExpUmpXbC80R0RtMitqdlBvWU90cGJHRWo5ZE40U0tUT1VSMlV1T2JpSEViSVBibWkzNS84OHRwK0VPS29zalhUbk1VRS9SVkJWWWtzT3pMdHdJN2U1YjdsUm1WbEF4ckJnU1BPeFJiMGlGaG5oUUZPODdUYTRDbWFvaE5Xd0U1YkNuRUNDUk9rUXF1TUJNdy9jeGFnZUUySjJjVWlIRG5SRUFPK2NkcFV5TGpRS1hJMk5sdnJvSUtBN094OGFTWFo3OHFJM1gvYm1vWUVRdGFheTJMNklSYU9MbWE1ZUg4ck13c2VPKzM3aW1vL0RQRjlKQmwwZk9Sckc2NzMwQnJrYlVyalNrQzcwM0xDc2RROTN4R1lpNzVBMnV4aGhZSGVqMHRta3ovMEJGK1owUDZkZ01PZmhKdm9uTHR3ZHpmZWlmNFovZVRRRWtvRlR0bXMzMzBVczFIT09xeXlBUVpScEk2NVB4eThycW1Qa0ZuVldYL3o3NDROS1MzRTQzT1FwdmNnQUt4MW5CeWMyUHkwRTJpUFRYWjB1cVhNdTNuQnlPUUNHYmJHeWc4OFNzWFZzV3JjNmRJYzhhSDIzOVRKS2QzN1BRYXMxcmpTTUxRMWMxelZuT2l2UDRINXhmZ2J6RjFlZW44UHlJZ2k3emMvV2ZLTWNGZVlHNFNKYUNKNzkwK1gxM1VVb0g2UGF1NlhMUT09IiwicmVxdWVzdElkIjoiZTcxZWI4MDctZWRjZC00ZjU4LWE0NGItYzIzOWQwODMzNDlhIiwidmVyc2lvbiI6InYxIn0=.d66eaec0536b0c829bf8d322aae9163d",
            "cosy_key": "OsMldKM6ntTY8FwW9UeQyFYzfpihzkAKz5aPdWqJsxLdKhVGnKGPwqf1zfq9uLQeWLQOJtC0o4RHs3SFK3UxKCRsXKcZ5y90lqUc+0ooDP9l5Yb86FhcdVLhnTbgxMwXUByK/WDT/0YA/PAPzN6UkUdXQPvNnnLU5/XM7drZ+Ks="
        }
        
    def _get_common_headers(self) -> Dict[str, str]:
        """获取通用请求头"""
        return {
            "User-Agent": "Go-http-client/2.0",
            "Accept-Encoding": "identity",
            "Content-Type": "application/json",
            "Cache-Control": "no-cache",
            "cosy-version": self.device_info["cosy_version"],
            "cosy-user": self.user_info["id"],
            "cosy-clientip": self.device_info["cosy_clientip"],
            "cosy-clienttype": self.device_info["cosy_clienttype"],
            "cosy-machineid": self.device_info["cosy_machineid"],
            "login-version": self.device_info["login_version"],
            "cosy-date": str(int(time.time())),
            "x-request-id": str(uuid.uuid4()),
            "authorization": f"Bearer {self.auth_tokens['bearer_token']}",
            "cosy-key": self.auth_tokens["cosy_key"]
        }
    
    def check_user_status(self) -> Dict[str, Any]:
        """检查用户状态 - 对应lingma1.txt"""
        url = f"{self.base_url}/algo/api/v3/user/status?Encode=1"
        headers = self._get_common_headers()
        headers["accept"] = "application/json"
        
        # 从lingma1.txt提取的加密请求体
        encrypted_body = "au(tLuLf*lLf*xoBrxoKhDSFzaOFONOF^Pgf*lODiuZjLGgf*#xFwPTLhDOWNBM)Xexw*GoKLuOjbDHFSDxK^PSWhBMn*V,KW@d*VR#QDRiMDSgNB*%NBEdLNEjbuOgrFHWUDSQNBM)NBLf*Ggf*N(FMJxK)JZLv#xFwPgCbP(FhxoByxoKNB*%NBEKLDEKLN(imYKf#xLru(gzBMn*m.f*JxjLNzLzxoByxoBYV@&YjMV(j@#(jMBwVRVkjRFNB*%NBOWYDwLzxoByxoB(jOjLD@a(jRdilHpwl"
        
        try:
            response = requests.post(url, headers=headers, data=encrypted_body, timeout=30)
            print(f"用户状态检查 - 状态码: {response.status_code}")
            print(f"响应头: {dict(response.headers)}")
            
            if response.status_code == 200:
                return response.json()
            else:
                print(f"请求失败: {response.text}")
                return {"error": f"HTTP {response.status_code}"}
                
        except Exception as e:
            print(f"请求异常: {str(e)}")
            return {"error": str(e)}
    
    def agent_chat(self, encrypted_body: str) -> Dict[str, Any]:
        """发送agent聊天请求"""
        url = f"{self.base_url}/algo/api/v2/service/pro/sse/agent_chat_generation"
        params = {
            "FetchKeys": "llm_model_result",
            "AgentId": "agent_common", 
            "Encode": "1"
        }
        
        headers = self._get_common_headers()
        headers["accept"] = "text/event-stream"
        headers["content-length"] = str(len(encrypted_body))
        
        try:
            response = requests.post(url, headers=headers, params=params, data=encrypted_body, timeout=30)
            print(f"Agent聊天请求 - 状态码: {response.status_code}")
            
            if response.status_code == 200:
                # 处理SSE响应
                return self._parse_sse_response(response.text)
            else:
                print(f"请求失败: {response.text}")
                return {"error": f"HTTP {response.status_code}"}
                
        except Exception as e:
            print(f"请求异常: {str(e)}")
            return {"error": str(e)}
    
    def _parse_sse_response(self, sse_text: str) -> Dict[str, Any]:
        """解析SSE响应"""
        lines = sse_text.strip().split('\n')
        messages = []
        
        for line in lines:
            if line.startswith('data:'):
                try:
                    data_str = line[5:].strip()  # 移除 'data:'
                    if data_str and data_str != '[DONE]':
                        data = json.loads(data_str)
                        if 'body' in data and data['body'] != '[DONE]':
                            body = json.loads(data['body'])
                            if 'choices' in body and body['choices']:
                                delta = body['choices'][0].get('delta', {})
                                if 'content' in delta:
                                    messages.append(delta['content'])
                except json.JSONDecodeError:
                    continue
        
        return {
            "success": True,
            "content": "".join(messages),
            "message_count": len(messages)
        }
    
    def simulate_conversation(self):
        """模拟完整对话流程"""
        print("=" * 60)
        print("开始模拟Tongyi Lingma API调用流程")
        print("=" * 60)
        
        # 1. 检查用户状态
        print("\n1. 检查用户状态...")
        user_status = self.check_user_status()
        print(f"用户状态结果: {user_status}")
        
        # 2. 模拟第一个agent请求 (lingma2.txt)
        print("\n2. 发送第一个agent请求...")
        encrypted_body_1 = "V(FNuh,WbAmasHJbuSWMPAPiihPmtL%h#Hd&SA,XnAm&&mSJL..&#HdNuL%.VR_^#YWnPxjwukKQxZafVRjLxHXLbDvL*#kOMQR)LyIyBlmaEAPBzl,XnAm&&mP^slOZ*L%h#Hd&SA,XnAm&&mSJL..&#HdNuh*AzASZhMn&QQ,eQn*pQGhMQyodQUlny#mcxHQNu*VMBlmzhh,A*Y_^lL%hQ#yHQ#AYQPAQycAJycyfQu(FlL%hxZafVRjMPHL^JHWYmF%.VR_^DF%hQQ,eQn*pQGhMQyodQUlny#mcxHQ&#HduQGhMQyodQD(xxSd&#g%hxZafVRjMG(i)NkCbNELNJ@_fV(FNuL%.VR_^#(i)NkCbNELNJ@_fV(FNuh,WbAmaslP^Lm*bUF%h#Hd&SA,X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^xkKL#xjbuOLhDYByDOgrN(arBOgfPFWUDxz*l*B*GoK.NOf*l*B*GoK^ukFY#(a*l*B*GoKt#xiePSQfJxCeJHWUDSQ^BMnfe,f*uSF^N(gEDxV*lLtXBEKbuHa*l*K^mxjwDSw*GoKMu(QwDSQwBMn*QG(&Q)*bQG*_QG*sQnApyDmhQ),QQ#PDQG*@QPy(XXYVQG*@yDmnyG,eyG,MQQoHycmMQPAQycAJQG*cQG*GQ)PZQuO(Q),QQ#PDQu(@Q#OjQnApyDmhIIooycAkQDAyQGslQGhLQG*GQGAiQnHblL%hxHI%G*RLMnuLMXGLUXEnUQknUURLbDayBg%.VR_^#(i)NkCbNELNJ@_fV(FNuMBhBlSWzASKMmPvzlOxUMn&xZafVRjM#kFYNOFhJgW%JSF^JHLbuL%.VR_^DF%hxHXzhXbL*sZn)nZOr#ByxHI%G*RL*BuOE)RLbDvL*#kOMQR)LyXzhckEOn@zhyvnUIkLzn^EEBZELPxzbyZO&PWNuMBhBlP&hmPjUhSlihSvrhSbhm*bEmPKbhSZhhSbhmSyLlmPilShMlPFtlPViA,XnASbhm*%nF%hVYI&QuoHQnApyDmhQ),QQ#PDQG*yQPyVQ)SwIIodQ)*lQyHhQG*aQIhrQyhGQQsTQu(*QuYvxHIwG*RzbQkOMBZLM)!OMQR)LyXEOn@OnGMLbIvOiB!LOXXzhBkLMQiNuMahBlmiUh,!EmPahmSHOmSpMhmPilPvzlOxUhSjrA,WbA*TrmmOhA,I*h,I*APSiA,QEA*Rbm**sAmpih*En.%hj*I&"
        
        result_1 = self.agent_chat(encrypted_body_1)
        print(f"第一个请求结果: {result_1}")
        
        # 3. 模拟第二个agent请求 (lingma3.txt)
        print("\n3. 发送第二个agent请求...")
        encrypted_body_2 = "wPSWhxHQM#xCLD(WYm@n&PHL^JHWYmFWw#xjUxkJbNOtOuHWkxHQNJ@_fV(Vb#(WhJHFhJg%.VR_^DF%hxHIMBT.LuSWYm,_YxHQNJ@_fV(jMu(QwDSQwxZafV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&PSI&JHiLBZdYu()L#kprBZj.#(&&#xV&NkdL#(LOPSFzBZFhPxp&JHF^JHLhDYdONOgtDxJbNOt^GodONOWhJo.LuOp&#(WtNHWhDSQwBH%)#EKiNOLLNYf&J(F*BHDY#S.LJ(WYPkVrBHFw#YQNu*_&G,dpNOWsDSjwBTjbuOD)DkFY#xC)u(IyBTK.PS%zBZCbu(%^GodzDxdLuOCLuOjQBH.iuOgEDS.LuEprBZdYu()L#kp&DSQ(PxKbuO.LuEp&#(WhDOLEJxKiJHLbu*f&DxCMGL%hBo_tBTFhJOLYu(QtDSQwBTjbuOD)DkFY#xC)u(IyBgK.uEC)uSa&DSQ(PxKbuO.LuEp&#(WhDOLEJxKiJHLbu*f&DSQ(PxKbuO.LuEp&JOgYPSg*uHF^GodzDxdLuOCLuOj)DxVrBT)T,Ydf#xCnNYf&DxCMGL%hG,dpNOWsDSjwBgjfD"
        
        result_2 = self.agent_chat(encrypted_body_2)
        print(f"第二个请求结果: {result_2}")
        
        print("\n=" * 60)
        print("模拟完成！")
        print("=" * 60)

def main():
    """主函数"""
    print("Tongyi Lingma API 模拟器")
    print("基于真实监听数据构建的API调用工具\n")
    
    simulator = LingmaAPISimulator()
    simulator.simulate_conversation()

if __name__ == "__main__":
    main()